
#ifndef _SDK_GLOBAL_H
#define _SDK_GLOBAL_H


#include <QtCore>

/*!
  Private member name
  */
#define O_PRIVATE_NAME _d_ptr_

/*!
  Forward declaration of Private class
  */
#define O_PRIVATE_DECLARE(classname) class classname##Private

/*!
  Declare private member macro.
  This macro declarate private member and make it as friend class to base
  \sa O_PRIVATE_NAME
  \sa O_D
  \sa O_PRIVATE_CREATE
  \sa O_PRIVATE_DELETE
  */
#define O_PRIVATE_DECLARE_MEMBER(classname) \
    classname##Private * const O_PRIVATE_NAME; \
    inline classname##Private* d_func() { return reinterpret_cast<classname##Private* >(oGetPtrHelper(O_PRIVATE_NAME)); } \
    inline const classname##Private* d_func() const { return reinterpret_cast<classname##Private* >(oGetPtrHelper(O_PRIVATE_NAME)); } \
    friend class classname##Private;

/*!
  Macro to create (initialize) Private member (it should be put into constructor initialize list)

  \code
  SomeClass::SomeClass():
    O_PRIVATE_CREATE(SomeClass)
  {
      ...
  }
  \endcode
  \sa O_D
  \sa O_PRIVATE_DELETE
  */
#define O_PRIVATE_CREATE(classname) O_PRIVATE_NAME(new classname##Private)

/*!
  Delete provate member (it should be put into destructor)
  \code
  SomeClass::~SomeClass()
  {
      ...
      O_PRIVATE_DELETE;
  }
  \endcode
  \sa O_D
  \sa O_PRIVATE_CREATE
  */
#define O_PRIVATE_DELETE delete O_PRIVATE_NAME;


/*!
  Create variable \b d as pointer to provate object
  \code
  O_D(SomeClass);
  d->someClassMember = value;
  \endcode
  \sa O_PRIVATE_CREATE
  \sa O_PRIVATE_DELETE
  */
#define O_D(classname) classname##Private * d = d_func();
#define O_C(classname) O_D(const classname)

#define O_PRIVATE O_PRIVATE_NAME
#define OP O_PRIVATE

template <typename T> static inline T *oGetPtrHelper(T *ptr) { return ptr; }

#endif // _SDK_GLOBAL_H
